
var pictures = new Array();//Массив картинок
var preload = new Array();//Массив картинок

preload.push({t: "resource", i: "hp", e: "png"});
preload.push({t: "resource", i: "mp", e: "png"});
preload.push({t: "resource", i: "hp_allies", e: "png"});
preload.push({t: "resource", i: "hp_allies_hero", e: "png"});
preload.push({t: "resource", i: "hp_anemy", e: "png"});
preload.push({t: "resource", i: "hp_anemy_hero", e: "png"});
preload.push({t: "heroes/juggernaut", i: "run", e: "png"});
preload.push({t: "heroes/juggernaut", i: "stand", e: "png"});
preload.push({t: "heroes/juggernaut", i: "atack1", e: "png"});
preload.push({t: "heroes/juggernaut", i: "atack2", e: "png"});
preload.push({t: "heroes/juggernaut", i: "atack3", e: "png"});

preload.push({t: "heroes/bloodseeker", i: "run", e: "png"});
preload.push({t: "heroes/bloodseeker", i: "stand", e: "png"});
preload.push({t: "heroes/bloodseeker", i: "atack1", e: "png"});
preload.push({t: "heroes/bloodseeker", i: "atack2", e: "png"});
preload.push({t: "heroes/bloodseeker", i: "atack3", e: "png"});

preload.push({t: "heroes/clinkz", i: "run", e: "png"});
preload.push({t: "heroes/clinkz", i: "stand", e: "png"});
preload.push({t: "heroes/clinkz", i: "atack1", e: "png"});
preload.push({t: "heroes/clinkz", i: "atack2", e: "png"});
preload.push({t: "heroes/clinkz", i: "atack3", e: "png"});
preload.push({t: "heroes/clinkz", i: "arrow", e: "png"});
preload.push({t: "heroes/clinkz", i: "explosion", e: "png"});

preload.push({t: "heroes/dragonknight", i: "run", e: "png"});
preload.push({t: "heroes/dragonknight", i: "stand", e: "png"});
preload.push({t: "heroes/dragonknight", i: "atack1", e: "png"});
preload.push({t: "heroes/dragonknight", i: "atack2", e: "png"});
preload.push({t: "heroes/dragonknight", i: "atack3", e: "png"});


preload.push({t: "heroes/invoker", i: "run", e: "png"});
preload.push({t: "heroes/invoker", i: "stand", e: "png"});
preload.push({t: "heroes/invoker", i: "atack1", e: "png"});
preload.push({t: "heroes/invoker", i: "atack2", e: "png"});
preload.push({t: "heroes/invoker", i: "atack3", e: "png"});
preload.push({t: "heroes/invoker", i: "arrow", e: "png"});
preload.push({t: "heroes/invoker", i: "explosion", e: "png"});

preload.push({t: "heroes/necrophos", i: "run", e: "png"});
preload.push({t: "heroes/necrophos", i: "stand", e: "png"});
preload.push({t: "heroes/necrophos", i: "atack1", e: "png"});
preload.push({t: "heroes/necrophos", i: "atack2", e: "png"});
preload.push({t: "heroes/necrophos", i: "atack3", e: "png"});
preload.push({t: "heroes/necrophos", i: "arrow", e: "png"});
preload.push({t: "heroes/necrophos", i: "explosion", e: "png"});

preload.push({t: "heroes/sven", i: "run", e: "png"});
preload.push({t: "heroes/sven", i: "stand", e: "png"});
preload.push({t: "heroes/sven", i: "atack1", e: "png"});
preload.push({t: "heroes/sven", i: "atack2", e: "png"});
preload.push({t: "heroes/sven", i: "atack3", e: "png"});

preload.push({t: "heroes/warlock", i: "run", e: "png"});
preload.push({t: "heroes/warlock", i: "stand", e: "png"});
preload.push({t: "heroes/warlock", i: "atack1", e: "png"});
preload.push({t: "heroes/warlock", i: "atack2", e: "png"});
preload.push({t: "heroes/warlock", i: "atack3", e: "png"});
preload.push({t: "heroes/warlock", i: "arrow", e: "png"});
preload.push({t: "heroes/warlock", i: "explosion", e: "png"});

preload.push({t: "heroes/wraithking", i: "run", e: "png"});
preload.push({t: "heroes/wraithking", i: "stand", e: "png"});
preload.push({t: "heroes/wraithking", i: "atack1", e: "png"});
preload.push({t: "heroes/wraithking", i: "atack2", e: "png"});
preload.push({t: "heroes/wraithking", i: "atack3", e: "png"});
function preloadPicture(N) {
    if (N < preload.length) {
        //$(function() {$("#loading .progressbar").progressbar( "value", Math.floor((N/preload.length)*50));});
        var img = pushPicture(preload[N].t, preload[N].i, preload[N].e);
        img.onload = function() {
            var pr = Math.round(N / preload.length * 100);
            $("#log").html("Loading " + pr + "%");
            preloadPicture(N + 1);
            if ((N + 1) == preload.length) {

            } else {
            }
        }
        img.onerror = function() {
            alert("Ошибка загрузки: img/" + preload[N].t + "/" + preload[N].i + "." + preload[N].e);
            preloadPicture(N + 1);
        }
    } else {
        endPreloadImg();
    }
}
function pushPicture(t, i, exp) {
    var img = new Image();
    img.src = "img/" + t + "/" + i + "." + exp;
    img.name = t + " " + i + "." + exp;
    img.created = new Date().getTime();
    //img.width = 0;
    img.onerror = function() {
        alert(img.src);
    }
    //img.created = TimeNewMsg;
    pictures.push(img);
    return img;
}
;
function getPicture(t, i, exp) {
    var img = null;
    for (var j = 0; j < pictures.length; j++) {
        if (pictures[j].name == t + " " + i + "." + exp) {
            img = pictures[j];
        }
    }
    if (img == null) {
        img = pushPicture(t, i, exp);
    }
    return img;
}
;



